public with sharing class MC_NewSignupsController
{
    public Id MissionalCommunityId {get; set;}
    
    public List<Missional_Community_Member__c> Members
    {
        get
        {
            if(Members==null)
            {
                DateTime twentyFourHoursAgo=DateTime.now().addDays(-1);
                Members=
                [
                    select
                        id
                        ,contact__r.Name
                        ,contact__r.gender__c
                        ,contact__r.Phone
                        ,contact__r.Email
                            ,date_joined__c
                            ,has_been_contacted__c
                            ,interested_in_joining__c
                            ,invitation_sent__c
                    from
                        Missional_Community_Member__c
                    where
                        missional_community__c=:MissionalCommunityId
                        and role__c<>'Leader'
                        and has_been_contacted__c=false
                        and date_joined__c > :twentyFourHoursAgo
                    order by
                        date_joined__c
                ];
            }
            
            return Members;
        }
        
        set;
    }
    
    public static testMethod void test1()
    {
    	//Put together some test data
    	Missional_Community__c aGroup=new Missional_Community__c();
    	Contact aLeader=new Contact();
    	aLeader.AccountId=[select id from Account where Name='Missional Community Members' limit 1].Id;
    	aLeader.FirstName='LeaderFirst';
    	aLeader.LastName='LeaderLast';
    	aLeader.Email='leader@email.bad';
    	insert aGroup;
    	insert aLeader;
    	Missional_Community_Member__c aGroupMember=new Missional_Community_Member__c();
    	aGroupMember.Contact__c=aLeader.Id;
    	aGroupMember.Missional_Community__c=aGroup.Id;
    	aGroupMember.Role__c='Leader';
    	insert aGroupMember;
    	
    	Contact aMember1=new Contact();
    	aMember1.AccountId=[select id from Account where Name='Missional Community Members' limit 1].Id;
    	aMember1.FirstName='Member1First';
    	aMember1.LastName='Member1Last';
    	aMember1.Email='member1@email.bad';
    	insert aMember1;
    	Missional_Community_Member__c aGroupMember2=new Missional_Community_Member__c();
    	aGroupMember2.Contact__c=aMember1.Id;
    	aGroupMember2.Missional_Community__c=aGroup.Id;
    	aGroupMember2.Role__c='Member';
    	aGroupMember2.Date_Joined__c=DateTime.now().addDays(-1).addHours(-5);
    	insert aGroupMember2;
    	
    	Contact aMember2=new Contact();
    	aMember2.AccountId=[select id from Account where Name='Missional Community Members' limit 1].Id;
    	aMember2.FirstName='Member2First';
    	aMember2.LastName='Member2Last';
    	aMember2.Email='member2@email.bad';
    	insert aMember2;
    	Missional_Community_Member__c aGroupMember3=new Missional_Community_Member__c();
    	aGroupMember3.Contact__c=aMember2.Id;
    	aGroupMember3.Missional_Community__c=aGroup.Id;
    	aGroupMember3.Role__c='Member';
    	aGroupMember3.Date_Joined__c=DateTime.now().addHours(-5);
    	insert aGroupMember3;
    	
    	
    	MC_NewSignupsController controller=new MC_NewSignupsController();
    	controller.MissionalCommunityId=aGroup.Id;
    	
    	Boolean foundPositive=false;
		Boolean foundNegative=false;
		for(Missional_Community_Member__c member : controller.Members)
		{
			if(member.id==aGroupMember2.id)
				foundNegative=true;
			if(member.id==aGroupMember.id)
				foundNegative=true;
			if(member.id==aGroupMember3.id)
				foundPositive=true;
		}
		System.assertEquals(true, foundPositive);
		System.assertEquals(false, foundNegative);
    }
}